# 模型资源消耗
def product_consume(feature_name):
    prod_simp = ['score','mrp','mrf','als_','alm_','ald_','tl_','aln_','ql_','ae_','alfp_','ip_','afm_','rc_','aae_','atmaep_','atmalfp_','atmalsp_','atmqlp_','atmtlp_','cc_','aae_','afw_','ala_','afc_','at_','il_','frg_','gl_','gl_','ir_','irp_','pd_','cf_','mma_','mmb_','cof_','sl_','stab_','alu_','cv_','aps_']
    df_count = pd.DataFrame()
    for t in range(len(prod_simp)):
        df_temp = pd.DataFrame({prod_simp[t]:[i for i in feature_name if re.match(prod_simp[t],i)]})
        if len(df_temp) != 0:
            df_count = pd.concat([df_count,df_temp],axis = 1)
        else:
            pass
    var_use = ['mrp_','mrf_','als_','alm_','ald_','tl_','aln_','ql_','ae_','alfp_','ip_','afm_','rc_','aae_','atmaep_','atmalfp_','atmalsp_','atmqlp_','atmtlp_','cc_','aae_','afw_','ala_','afc_','il_','frg_','gl_','ir_','irp_','pd_','cf_','mma_','mmb_','cof_','sl_','stab_','alu_','cv_','aps_']
    pro_use = [12.26,40.05,10.7,8.68,1.5,8.6,22.26,5.4,2.2,4.29,7.43,3.2,12.04,4.8,10.34,3.98,23.27,17.37,10.61,14.5,10.27,5.74,9.19,10.35,4.7,1.7,3.31,3,5.26,2,5.9,5.5,1.6,3.5,2.2,2,3.5,2.59,14.18]
    dict_use = {i:j for i,j in zip(var_use,pro_use)}
    prod_consume = sum([dict_use.get(key, 0) for key in df_count.columns])
    return df_count.replace(np.nan,""),prod_consume

df_count,prod_consume = product_consume(feature_df.feature_name)
df_count

# 批量加入入模变量
def feature_module(final_features):
    import re
    df_feature = pd.DataFrame(final_features,columns = ['入模原始变量']).sort_values(by = '入模原始变量')
    df_feature['类别'] = '画像'
    df_feature['入模模块'] = np.nan

    var_dict = {
        'tl': 'TotalLoan-V2.0',
        'ae': 'ApplyEvaluate-V1.0',
        'pd': 'PopulationDerivation-V2.0',
        'alf':'ApplyFeature-V3.0',
        'mma':'MultipleModelA-V1.0',
        'stab':'Stability_c-V2.0',
        'als':'ApplyLoanStr-V2.0',
        'ir':'InfoRelation-V3.0',
        'cf':'ConsumptionFeature-V1.0',
        'alu':'ApplyLoanUsury-V1.1',
        'gl':'GrayListExpand-V1.0',
        'mmb':'MultipleModelB-V1.0',
        'ql':'QuantileLevel-V1.0',
        'tl':'TotalLoan-V2.0',
        'frg':'FraudRelation_g-V1.0',
        'aes':'ApplyEvaluateStr-V1.0',
        'ald':'ApplyLoan_d-V2.3',
        'rc':'RiskChar-V1.0',
        'rpp':'RiskPreferPre-V1.0',
        'atmaep':'ApplyTrendMixAePro-V1.0',
        'atmalfp':'ApplyTrendMixAlfPro-V1.0',
        'atmalsp':'ApplyTrendMixAlsPro-V1.0',
        'atmtlp':'ApplyTrendMixTlPro-V1.0',
        'atmqlp':'ApplyTrendMixQlPro-V1.0',
        'aae':'ApplyApprovalEvaluate-V1.0',
        'aps':'ApplyPreferStable-V1.0',
        'aln':'ApplyLoanNewSub-V1.0',
        'ip':'InterestPrefer-V3.0',
        'afm':'ApplyFeatureMix-V1.0'
    }

    flag_dict = {
        'tl': 'flag_totalloan',
        'ae': 'flag_applyevaluate',
        'pd': 'flag_populationderivation',
        'alf':'flag_ApplyFeature',
        'mma':'flag_multiplemodela',
        'stab':'flag_stability_c',
        'als':'flag_applyloanstr',
        'ir':'flag_inforelation',
        'cf':'flag_ConsumptionFeature',
        'alu':'flag_applyloanusury',
        'gl':'flag_graylistexpand',
        'mmb':'flag_multiplemodelb',
        'ql':'flag_quantilelevel',
        'tl':'flag_totalloan',
        'frg':'flag_fraudrelation_g',
        'aes':'flag_applyevaluatestr',
        'ald':'flag_applyloan_d',
        'rc':'flag_riskchar',
        'rpp':'flag_riskpreferpre',
        'atmaep':'flag_applytrendmixaepro',
        'atmalfp':'flag_applytrendmixalfpro',
        'atmalsp':'flag_applytrendmixalspro',
        'atmtlp':'flag_applytrendmixtlpro',
        'atmqlp':'flag_applytrendmixqlpro',
        'aae':'flag_applyapprovalevaluate',
        'aps':'flag_applypreferstable',
        'aln':'flag_applyloannewsub',
        'ip':'flag_interestprefer',
        'afm':'flag_applyfeaturemix'
    }

    product_list = list(set([i[0:i.find('_')] for i in df_feature['入模原始变量'].tolist()]))

    for i in product_list:
        temp_var = [t for t in df_feature['入模原始变量'].tolist() if re.match(i,t)]
        df_feature.loc[df_feature['入模原始变量'].isin(temp_var),'入模模块'] = var_dict[i]
        df_feature = df_feature.append([{'入模原始变量':flag_dict[i],'类别':'画像','入模模块':var_dict[i]}], ignore_index=True)
    return df_feature

feature_module(feature_list)[['入模模块','入模原始变量','类别']].to_excel('桔子模型特征文件（入模模块及入模变量）.xlsx',index = False)